<?php
/**
 * TinyCorePHP Model基类
 * @author 	itkele@gmail.com
 * @date 	2013-02-17
 */
class Model{
	
	public $dbr;
	public $dbw;
	public $dbconfig;
	
	public function __construct(){
		//
	}
	
	public function query($sql){
		if(empty($sql)){
			return false;
		}
		$dbconfig = C('dbr');
		$dbr = new Db($dbconfig['db_host'], $dbconfig['db_user'], $dbconfig['db_pswd'], $dbconfig['db_name'] , $dbconfig['db_charset'] ,$dbconfig['pconnect']);
		$result = $dbr->get_array($sql);
		$dbr->close();
		
		return $result;
	}
	
	public function execute($sql,$returnLastid=false){
		if(empty($sql)){
			return false;
		}
		$dbconfig = C('dbw');
		$dbw = new Db($dbconfig['db_host'], $dbconfig['db_user'], $dbconfig['db_pswd'], $dbconfig['db_name'] , $dbconfig['db_charset'] ,$dbconfig['pconnect']);
		$result = $dbw->query($sql);
		if($returnLastid){
			$result = $dbw->insert_id();
		}
		$dbw->close();
		
		return $result;
	}

	public function __destruct(){
		//
	}
}
?>